﻿using Gufa.Entity;
using Microsoft.EntityFrameworkCore;
using System.Data;
using System.Reflection;

namespace Gufa.EntityFrameworkCore
{
    public class GufaDBContext : DbContext
    {
        public DbSet<Tech> Teches { get; set; }
        public DbSet<Award> Awards { get; set; }
        public DbSet<Experience> Experience { get; set; }
        public DbSet<Responsibility> Responsibilities { get; set; }
        public DbSet<ProjectInfo> ProjectInfos { get; set; }

        public GufaDBContext(DbContextOptions<GufaDBContext> opts) : base(opts) { }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            var assembly = Assembly.LoadFrom(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Gufa.Entity.dll"));
            var types = assembly.GetTypes();
            foreach (var type in types)
            {
                modelBuilder.ApplyConfigurationsFromAssembly(type.Assembly);
            }
        }
    }
}
